package com.mproject.service;

import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

// POJO, no interface no extends

// The class registers its methods for the HTTP GET request using the @GET annotation. 
// Using the @Produces annotation, it defines that it can deliver several MIME types,
// text, XML and HTML. 

// The browser requests per default the HTML MIME type.

//Sets the path to base URL + /hello
@Path("/myservices")
public class MessageService {

	String json_response="{\"#error\": false,";
	String error_msg="{\"#error\": true,\"#data\": {\"messgae\": \"error\"}}";

	@Produces ("text/plain")
	@GET 
	@Path("/update")
	public String updateUserInfo(@QueryParam("userid") String userid,
			@QueryParam("name") String name,
			@QueryParam("regid") String regid)
	{
		if (WebServiceMethods.UpdateUserInfo(userid, name, regid))
			return "{\"#error\": false}";
		else
			return error_msg;
	}

	//sending a message
	@Produces ("text/plain")
	@POST 
	@Path("/send")
	public String sendMessage(@FormParam("from") String from_sapid,
			@FormParam("to") String to_sapid,
			@FormParam("msg") String message,
			@FormParam("prj") String project_id,
			@FormParam("from_name") String from_name,
			@FormParam("prj_name") String project_name)
	{


		//System.out.println(json_response+"\"#data\":"+WebServiceMethods.sendMessage(from_sapid, to_sapid, message)+"}");
		return json_response+"\"#data\":"+WebServiceMethods.sendMessage(from_sapid, to_sapid, message, project_id,from_name,project_name);



	}	

}